package com.ukao.cashregister.widget;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * Created by ukaodev on 2017/5/25.
 */

public class NoScrollViewPager extends ViewPager{


        private boolean isCanScroll = false;

        public NoScrollViewPager(Context context) {
            super(context);
        }

        public NoScrollViewPager(Context context, AttributeSet attrs) {
            super(context, attrs);
        }

        public void setCanScroll(boolean isCanScroll){
            this.isCanScroll = isCanScroll;
        }
        @Override
        public void scrollTo(int x, int y){
//        if (isCanScroll){
            super.scrollTo(x, y);
//        }
        }

        @Override
        public void setCurrentItem(int item) {
            // TODO Auto-generated method stub
            super.setCurrentItem(item);
        }
        @Override
        public boolean onTouchEvent(MotionEvent arg0) {
            // TODO Auto-generated method stub
            if (isCanScroll) {
                return super.onTouchEvent(arg0);
            } else {
                return false;
            }
        }
        @Override
        public boolean onInterceptTouchEvent(MotionEvent arg0) {
            // TODO Auto-generated method stub
            if (isCanScroll) {
                return super.onInterceptTouchEvent(arg0);
            } else {
                return false;
            }
        }
}
